package org.dromara.demo.designPattern.观察者模式.service;

import org.dromara.demo.designPattern.观察者模式.entity.LotteryResult;
import org.dromara.demo.designPattern.观察者模式.event.MQEventListener;
import org.dromara.demo.designPattern.观察者模式.event.MessageEventListener;
import org.dromara.demo.designPattern.观察者模式.manager.EventManager;

public abstract class LotteryService2 {
    private EventManager eventManager;

    public LotteryService2() {
        eventManager = new EventManager(EventManager.EventType.MQ,
                EventManager.EventType.Message);
        eventManager.subscribe(EventManager.EventType.MQ, new MQEventListener());
        eventManager.subscribe(EventManager.EventType.Message, new MessageEventListener());
    }
    public LotteryResult draw(String uId) {LotteryResult lotteryResult = doDraw(uId);
// 需要什么通知就给调用什么方法
        eventManager.notify(EventManager.EventType.MQ, lotteryResult);
        eventManager.notify(EventManager.EventType.Message, lotteryResult);
        return lotteryResult;
    }
    protected abstract LotteryResult doDraw(String uId);
}
